﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamNitro.Student
{
    public partial class Students_AddElective : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DBManager_Jowie db = (DBManager_Jowie)Session["Student"];
            List<DBManager_Jowie> dbJowieRetrieve = DBManager_Jowie.GetElectiveSubjects(db.CourseCode);
            for (int i = 0; i < dbJowieRetrieve.Count; i++)
            {
                ddlElectiveName.Items.Add(dbJowieRetrieve[i].ElectiveName);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DBManager_Jowie db = (DBManager_Jowie)Session["Student"];
            List<DBManager_Jowie> dbJowie1 = DBManager_Jowie.GetElectiveSubjects(db.CourseCode);
            DBManager_Jowie dbJowie = new DBManager_Jowie();
            dbJowie.AdminNumber = db.AdminNumber;
            for (int i = 0; i < dbJowie1.Count; i++)
            {
                if (ddlElectiveName.SelectedValue == dbJowie1[i].ElectiveName)
                {
                    dbJowie.ElectiveCode = dbJowie1[i].ElectiveCode;
                    dbJowie.ElectiveName = dbJowie1[i].ElectiveName;
                    break;
                }
            }
            
            DBManager_Jowie.AddElectiveSubject(dbJowie);

            ddlElectiveName.Items.Clear();
            for (int i = 0; i < dbJowie1.Count; i++)
            {
                ddlElectiveName.Items.Add(dbJowie1[i].ElectiveName);
            }
        }
    }
}